<template>
	<view class="content">
		
		<!-- http://localhost:8080/?code=041z6b1w3w943Y2biy2w32IQj71z6b13&state=STATE#/pages/login/login -->
		
		<view class="iboxs">
			
			<image :src="about" mode=""></image>
			<view class="iboxs-title">充值</view>
			<view class="iboxs-login" @tap="submit()">
				立即登陆
			</view>
			<view class="iboxs-back"  @tap="back()">
				暂不登陆
			</view>
			
		</view>
	
		
		
	</view>
</template>

<script>
	
	
	import { getinfo } from 'common/api.js';
		
	export default {
		data() {
			return {
				code:'code',
				about:'',
				avatar:''
			}
		},
		
		onLoad(){
			
		
			getinfo('setting',{}).then((res)=>{
				console.log(res)
				this.appid=res.appid;
				this.about=res.data.logo;
			});
			
			var code = this.getUrlCode().code; // 截取code
			
			var agentid=uni.getStorageSync('agentid');
			console.log(agentid);
			
			if(code){
				var that=this;
				
				getinfo('login',{'code':code,agentid:agentid}).then((res)=>{
						console.log('************');
						console.log(res);
					if	(res.code==0){
						uni.setStorageSync('user',res.data);
						var url = window.location.host;
					
						setTimeout(function(){
							location.href="/h5#/pages/member/member";
						},50)
						
					}
				});
			}
	
			
		},
			
		onShow() {
			// console.log(encodeURIComponent('https://putian.vipwjf.com'));
			// return false;
			// 测试用 后面删除
			// getinfo('getuserinfo',{uid:4}).then((res)=>{
			// 		console.log('************');
			// 		console.log(res);
			// 	if	(res.code==0){
			// 		uni.setStorageSync('user',res.data);
			// 		setTimeout(function(){
			// 			location.href="/h5#/pages/member/member";
			// 		},50)
					
			// 	}
			// });
			
			
			var user=uni.getStorageSync('user');
			if	(user.id){
				uni.switchTab({
					url:"/pages/member/member"
				})
				return false;
			}
			
		},
			
		methods: {
			back(){
				
				location.href="/h5";
				// uni.switchTab({
				// 	url:"/pages/index/index"
				// })
			},
			submit(){
				// #ifdef H5
				let appid =this.appid;
				var url = location.href; 
				let uri=encodeURIComponent(url);
	
				var wxUrl ='https://open.weixin.qq.com/connect/oauth2/authorize?appid='+appid+
				'&redirect_uri=' +uri +'&response_type=code' +
				'&scope=snsapi_userinfo' +'&state=STATE#wechat_redirect';
				window.location.href = wxUrl;
				// #endif
			},
			
			
			getUrlCode() {
				// 截取url中的code方法
				var url = location.href; //获取打开的公众号的路径
				let winUrl = url;
				var theRequest = new Object();
				if (url.indexOf('?') != -1) {
					var str = url.substr(url.indexOf('?') + 1);
					var strs = str.split('&');
					for (var i = 0; i < strs.length; i++) {
						var items = strs[i].split('=');
						theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1];
					}
				}
				return theRequest;
			}
		}
	}
</script>

<style>
	.iboxs image{
		width: 180rpx;height: 180rpx;margin: auto;display: block;
	}
	.iboxs-title{
		width: 100%;height: 100rpx;line-height: 100rpx;text-align: center;font-size: 32rpx;font-weight: bold;
	}
	
	.iboxs-login{
		width: 500rpx;height: 90rpx;margin:10px auto;background: #14CB2E;color: #FFFFFF;text-align: center;
		line-height: 90rpx;border-radius: 90rpx;
	}
	.iboxs-back{
		width: 500rpx;height: 90rpx;margin:20px auto;color: #949494;text-align: center;
		line-height: 90rpx;border-radius: 90rpx;border: 1px solid #ececec;
	}
.iboxs{
	width: 600rpx;height: 700rpx;border: 1px solid #FFFFFF;
	position: fixed;left: 0;top: 0;right: 0;bottom: 0;margin: auto;
}
.content{
	
}
</style>